package com.example.provider.javastudy.ram;

/**
 * All rights Reserved, Designed By www.maihaoche.com
 *
 * @Package com.example.demo.ram
 * @author: 红雪（hongxue@maihaoche.com）
 * @date: 2019/1/17 9:10 AM
 * @Copyright: 2017-2020 www.maihaoche.com Inc. All rights reserved.
 * 注意：本内容仅限于卖好车内部传阅，禁止外泄以及用于其他的商业项目
 */
public class VolatileTest {
    public static volatile int race = 0;

    public static void increase(){
        race++;
    }

    private static  final int COUNT = 10;

    public static void main(String[] args) {
        Thread[] threads = new Thread[COUNT];

        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j = 0;j<10000;j++){
                        increase();
                    }
                }
            });
            threads[i].start();
        }

        System.out.println(race);
    }
}
